// axios 配置

// 全局请求配置
import axios from "axios"
import Router from "./../router";
import {ElMessage} from "element-plus";

const headers = {
    // "Content-Type": "application/json",
    "Content-type": "application/x-www-form-urlencoded",
    "X-App-Platform" :"wechat",
    // "X-Access-Token": "NGIR37XBOah8d1u6AGMf4m6Efp4VncB4",
    "X-Access-Token": localStorage.getItem("access_token"),
};

// const baseURL = "https://influencer.cn/web/index.php?_mall_id=1&r=";
const baseURL = "https://wh.xiaohutiger.cn/web/index.php?_mall_id=1&r=";
// const baseURL = "https://8.140.30.131/web/index.php?_mall_id=1&r=";

export default {
    post: (url: string, data: object) => {
        return new Promise((resolve) => {
            axios({
                method: "POST",
                url: baseURL + url,
                data: data,
                headers: headers,
            }).then(res => {
                if(res.data.code == -1){
                    Router.push("/").then(()=>{
                        console.log("登录异常")
                    })
                } else {
                    resolve(res.data);
                }
            }).catch(err => {
                console.log(err)
                ElMessage.error(err)
            })
        })
    },
    get: (url: string, data: object) => {
        return new Promise((resolve) => {
            axios({
                method: "GET",
                url: baseURL + url,
                data: data,
                headers: headers,
            }).then(res => {
                if (res.data.code == -1) {
                    Router.push("/").then(() => {
                        console.log("登录异常")
                    })
                } else {
                    resolve(res.data);
                }
            }).catch(err => {
                ElMessage.error(err)
            })
        })
    },

}
















